/**   
 * @Title: LotteryRecordListAdapter.java 
 * @Package: com.esun.rabbit2.viewer.mainact.mylotteryact 
 * @Description: TODO(购彩记录列表通用adapter) 
 * @Author: Billy qigs@500wan.com   
 * @Date: 2011-8-29 下午05:09:08  
 * Copyright (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.viewer.mainact.mylotteryact.lotteryrecord;

import java.util.ArrayList;
import java.util.Hashtable;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.esun.config.Config;
import com.esun.config.Key;
import com.esun.config.Language;
import com.esun.ui.R;
import com.esun.util.log.EDebug;

/**
 * @ClassName: LotteryRecordListAdapter
 * @Description: TODO(购彩记录列表通用adapter)
 * @Author: Billy qigs@500wan.com
 * @Date: 2011-8-29 下午05:09:08
 */
public class LotteryRecordListAdapter extends BaseAdapter {

	private String lotID;
	private LayoutInflater listInflater;
	// private ArrayList<View> recordListView = new ArrayList<View>();
	private ArrayList<Hashtable<String, String>> list = new ArrayList<Hashtable<String, String>>();

	private TextView tvPlayName;
	private TextView tvTime;
	private TextView tvPayMoney;
	private TextView tvIssucState;
	private TextView tvWinMoney;
	private TextView tvLotteryState;
	private TextView tvLotName;
	
	private ImageView imgArrow;

	private LinearLayout linearIssuc;

	private static final String TOTAL = "0";
	private static final String YES = "yes";
	
	private LotteryKindJudgment lotterykindjudgment;
	public LotteryRecordListAdapter(Context context, ArrayList<Hashtable<String, String>> tempList, ArrayList<View> tempViewList, String lotid) {
		this.listInflater = LayoutInflater.from(context);
		this.list = tempList;
		// this.recordListView = tempViewList;
		this.lotID = lotid;
		lotterykindjudgment = new LotteryKindJudgment();
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		// return recordListView.get(position);
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub

		if (list.get(position).get(Key.KEY_ISTITLE).equals(YES)) {

			convertView = listInflater.inflate(R.layout.lotteryrecord_listtable_title, null);

			((TextView) convertView.findViewById(R.id.lotteryrecord_listtable_title_tv_lotteryDate)).setText(list.get(position).get(Key.KEY_ADDDATE));
			convertView.setEnabled(false);
			return convertView;

		} else {
			convertView = listInflater.inflate(R.layout.lotteryrecord_listtable, null);

			tvPlayName = (TextView) convertView.findViewById(R.id.lotteryrecord_table_tv_playname);
			tvLotName = (TextView) convertView.findViewById(R.id.lotteryrecord_table_tv_lotName);
			tvPayMoney = (TextView) convertView.findViewById(R.id.lotteryrecord_table_tv_payMoney);
			tvTime = (TextView) convertView.findViewById(R.id.lotteryrecord_table_tv_lotteryTime);
			tvIssucState = (TextView) convertView.findViewById(R.id.lotteryrecord_table_tv_issuc);
			tvWinMoney = (TextView) convertView.findViewById(R.id.lotteryrecord_table_tv_getMoney);
			tvLotteryState = (TextView) convertView.findViewById(R.id.lotteryrecord_table_tv_lotteryState);
			linearIssuc = (LinearLayout) convertView.findViewById(R.id.lotteryrecord_table_linear_issuc);
			imgArrow = (ImageView) convertView.findViewById(R.id.lotteryrecord_table_imageview_arrow);

			// 全部里显示彩种
			if (lotID.equals(TOTAL)) {
				tvLotName.setText(list.get(position).get(Key.KEY_LOTNAME) + " " + list.get(position).get(Key.KEY_EXPECT) + "期");
				if (list.get(position).get(Key.KEY_LOTID).equals(Config.SHIYIXUANWU)) {
					linearIssuc.setVisibility(View.INVISIBLE);
				}
			} else {
				tvLotName.setText(list.get(position).get(Key.KEY_EXPECT) + "期");
				if (lotID.equals(Config.SHIYIXUANWU)) {
					linearIssuc.setVisibility(View.INVISIBLE);
				}
			}
			
			// 判断是否可以查看详情
			String getkindid = list.get(position).get(Key.KEY_LOTID);
			int tag = 2;//彩种判断方法参数。购彩记录处传2
			if (lotterykindjudgment.lotterykindsjudgment(Integer.parseInt(getkindid),tag)) {
				if (LotteryRecordTotalAct.isDanTuo(list.get(position).get(Key.KEY_PLAYID))) {
					imgArrow.setVisibility(View.INVISIBLE);
				}
			} else {
				imgArrow.setVisibility(View.INVISIBLE);
			}

			// 彩票标识
			if (list.get(position).get(Key.KEY_LOTID).equals(Config.SHIYIXUANWU)) {
				tvIssucState.setText("--");
			} else {
				if (list.get(position).get(Key.KEY_ISSUC).equals("0")) {
					tvIssucState.setText(Language.POPLOTTERYTIP_NOTISSUC);
				} else if (list.get(position).get(Key.KEY_ISSUC).equals("1")) {
					tvIssucState.setText(Language.POPLOTTERYTIP_ISSUCYET);
				}
			}
			tvPlayName.setText(list.get(position).get(Key.KEY_PLAYNAME));
			tvPayMoney.setText("￥" + list.get(position).get(Key.KEY_PAYMONEY).substring(0, list.get(position).get(Key.KEY_PAYMONEY).indexOf('.') + 3));
			tvTime.setText(list.get(position).get(Key.KEY_ADDTIME));
			// 中将状态
			EDebug.o(LotteryRecordListAdapter.this, "list adapter lottery state ==" + list.get(position).get(Key.KEY_STATE));
			if (list.get(position).get(Key.KEY_STATE).equals("0")) {
				tvLotteryState.setText(Language.MSG_DENGDAIKAIJIANG);
				tvWinMoney.setText("￥0.00");
				tvWinMoney.setTextColor(Color.BLACK);
			} else if (list.get(position).get(Key.KEY_STATE).equals("1")) {
				tvLotteryState.setText("未算奖");
				tvWinMoney.setText("￥0.00");
				tvWinMoney.setTextColor(Color.BLACK);
			} else if (list.get(position).get(Key.KEY_STATE).equals("2")) {
				tvLotteryState.setText("未中奖");
				tvWinMoney.setText("￥0.00");
				tvWinMoney.setTextColor(Color.BLACK);
			} else if (list.get(position).get(Key.KEY_STATE).equals("3")) {
				tvLotteryState.setText("已算奖");
				tvWinMoney.setText("￥0.00");
				tvWinMoney.setTextColor(Color.BLACK);
			} else if (list.get(position).get(Key.KEY_STATE).equals("4")) {
				tvLotteryState.setText("已派奖");
				tvWinMoney.setText("￥" + list.get(position).get(Key.KEY_GETMONEY));
			}

			return convertView;
		}

	}

}
